var currDT,courseType;
var today = new Date(); //获取完整日期
var years = today.getFullYear();//年
var month = today.getMonth()+1;//月
var dat = today.getDate();//日
var week = today.getDay()//周几
var weekDay = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; //星期几
var weeks = weekDay[week];
month = month < 9 ? "0"+month :month;
dat = dat < 10 ? "0"+dat :dat;


var jinri = years+"-"+month+"-"+dat;
var orderState = {"1":"已预约成功","2":"预约失败"};


$(function() {
	getQueryStringByName();
	
});
function getQueryStringByName(){
	courseType = slf.getQueryStringByName("courseType") || "";
}

//初始化日期 和选择日期之后
/*function initDate(startDate){
	slf.ajax({
		url : "/order/getSyllabusDate",
		success : function(data){
			var date = data.obj;
			var str = "";
			$("#time_ul").html("");
			var length = date.length;
			if(length > 7){
				length = 8;
			}
			if(!startDate){
				startDate = date[0];
				loadCourse(startDate);
			}
			for(var i = 0; i < length; i++){
				var mydate = new Date(date[i]);
				var myddy = mydate.getDay(); 
				var days=mydate.getDate();
				
				if(date[i] == startDate) {
					str += "<li class='times'><span>" + weekDay[myddy] + "</span><br><span class='timeDta selected'>"+days+"</span><br><span class='hidden' style='display:none'>"+date[i]+"</span></li>";
				} else {
					str += "<li class='times'><span>" + weekDay[myddy] + "</span><br><span class='timeDta'>"+days+"</span><br><span class='hidden' style='display:none'>"+date[i]+"</span></li>";
				}
				
			}
			$("#time_ul").html(str);
		}
	});
	time_click(); //日期点击事件
}*/



//选择日期
$('body').on('click','.times',function(){
	$(this).children('.timeDta').addClass('selected');
	$(this).siblings().children('.selected').removeClass('selected');
	var startDate = $(this).children('.hidden').text();
	$.ajax({
		url : "/course/getSyllabusListBySchool",
		data : {
			pageIndex : 1,
			pageSize : 20,
			startDate : startDate,
			courseType : courseType
		},
		success : function(data){
			if(data == ''){
				alert("空");
			}
			var course = data.obj.data;
			var html = "";
			for(var i = 0; i < course.length ; i++){
				var icon
				if(!course[i].iocn){
					icon = slf.defau.courseIcon(course[i].syllabusId);
				}else{
					icon = course[i].iocn.split(",");
				}
				var icons = icon.split(",");
				if(course[i].hotState = 1){
					html += "<div class='w100b radius4 over-hide  imgrx posi-rela am-margin-top-sm bottom-boshow2 bg-fff'>";
				}else if(course[i].newState = 1){
					html += "<div class='w100b radius4 over-hide classimg imgzx posi-rela am-margin-top-sm bottom-boshow2 bg-fff'>";
				}
				html+="<ul id='article' class='am-avg-sm-1 zjyy_div_ul margintop1'>";
				html+="<li class='dis-flex am-padding-top-sm am-padding-bottom-sm'>";
				html+='<div class="w35">';
				html+='<div class="img_div radius2 over-hid">';
				html += "<img onclick=\"javascript:window.location.href='basepkg_details.html?syllabusId="+course[i].syllabusId +"'\" src='"+icons[0]+"' class='w100b' />";
				html+='</div>';
				html+='</div>';
				html+='<div class="am-margin-left-xs  w65 flex1">';
				html+='<ul class="w100b am-avg-sm-1 kcxx">';
				html+='<li class="dis-flex"><span class="tilte w100b flex">'+course[i].courseName;
				if(course[i].vacancy > 0){
					if(course[i].orderState != -1){
						html += "<span class='text-28AD47 am-text-right font14 am-align-right am-margin-0'>"+slf.orderState[course[i].orderState]+"</span>";
					}
				}else{
					html += "<span class='text-28AD47 am-text-right font14 am-align-right am-margin-0'>已满</span>";
				}
				html += "</li>";
				html += "<li>"+course[i].description+"</li>";
				html += "<li>上课地点："+course[i].schoolName+" "+course[i].classroomName+"</li>";
				html += "<li>上课时间："+course[i].startDate+"</li>";
				html+='</ul>';
				html+='</div>';
				html+='</li>';
				html+='</ul>';
				html+='<ul class="w100b am-avg-sm-1 kcxx kcxx1 am-padding-sm bg-fff posi-rela">';
				html+='<li><span class="am-align-left am-margin-0">距离开课：</span>';
				html += "<div class='yomibox' data='"+course[i].startDate+"'></div>";
				html += "</li>";
				html += "<li class='kcyu_libtn' syllabusId='"+course[i].syllabusId +"'>";
				if(course[i].vacancy > 0){
					if(course[i].syllabusState != 5){
						if(course[i].isSchoolId != 0){
							html += "<button class='am-btn am-btn-sm an-btn-999 radius20 am-margin-top-sm am-btn-block posi-rela'>不在校区</button>";
						} else {
							if(course[i].orderState == 1){
								html += "<button class='am-btn am-btn-sm am-btn-blue radius20 am-margin-top-sm am-btn-block posi-rela'>取消预约</button>";
							} else if(course[i].orderState == -1 && course[i].purchaseState != 0){
								html += "<button class='am-btn am-btn-sm am-btn-blue radius20 am-margin-top-sm am-btn-block posi-rela'>立即预约</button>";
							}else if(course[i].orderState == -1 && course[i].purchaseState == 0){
								html += "<button class='am-btn font12 am-btn-sm am-btn-red radius20 am-margin-top-sm am-btn-block posi-rela'>购买课程</button>";
							}
						}          
					}else{
						html += "<button class='am-btn am-btn-sm an-btn-999 radius20 am-margin-top-sm am-btn-block posi-rela'>已结束</button>";
					}
				}
				html += "</li>";
				html += "</ul></div>";
			}
			$("#course").html(html);
			yomi.yomi();
		}
	})
	
})


//日期选择点击事件
function time_click() {
	//日期点击事件  并刷新内容
	var startDate = $("#time_ul .active .timeDta").html();
	$("body").on('click', '.kcyy3 li:not(:last-child)', function() {
		$(this).addClass("active").siblings().removeClass("active");
		startDate = $("#time_ul .active .timeDta").html();
		loadCourse(startDate);
	});
}

function loadCourse(startDate){
	slf.ajax({
		url : "/course/getSyllabusListBySchool",
		param : {
			pageIndex : 1,
			pageSize : 20,
			startDate : startDate,
			courseType : courseType
		},
		success : function(data){
			var course = data.obj.data;
			var html = "";
			for(var i = 0; i < course.length ; i++){
				var icon
				if(!course[i].iocn){
					icon = slf.defau.courseIcon(course[i].syllabusId);
				}else{
					icon = course[i].iocn.split(",");
				}
				var icons = icon.split(",");
				if(course[i].hotState = 1){
					html += "<div class='w100b radius4 over-hide  imgrx posi-rela am-margin-top-sm bottom-boshow2 bg-fff'>";
				}else if(course[i].newState = 1){
					html += "<div class='w100b radius4 over-hide classimg imgzx posi-rela am-margin-top-sm bottom-boshow2 bg-fff'>";
				}
				html+="<ul id='article' class='am-avg-sm-1 zjyy_div_ul margintop1'>";
				html+="<li class='dis-flex am-padding-top-sm am-padding-bottom-sm'>";
				html+='<div class="w35">';
				html+='<div class="img_div radius2 over-hid">';
				html += "<img onclick=\"javascript:window.location.href='basepkg_details.html?syllabusId="+course[i].syllabusId +"'\" src='"+icons[0]+"' class='w100b' />";
				html+='</div>';
				html+='</div>';
				html+='<div class="am-margin-left-xs  w65 flex1">';
				html+='<ul class="w100b am-avg-sm-1 kcxx">';
				html+='<li class="dis-flex"><span class="tilte w100b flex">'+course[i].courseName;
				if(course[i].vacancy > 0){
					if(course[i].orderState != -1){
						html += "<span class='text-28AD47 am-text-right font14 am-align-right am-margin-0'>"+slf.orderState[course[i].orderState]+"</span>";
					}
				}else{
					html += "<span class='text-28AD47 am-text-right font14 am-align-right am-margin-0'>已满</span>";
				}
				html += "</li>";
				html += "<li>"+course[i].description+"</li>";
				html += "<li>上课地点："+course[i].schoolName+" "+course[i].classroomName+"</li>";
				html += "<li>上课时间："+course[i].startDate+"</li>";
				html+='</ul>';
				html+='</div>';
				html+='</li>';
				html+='</ul>';
				html+='<ul class="w100b am-avg-sm-1 kcxx kcxx1 am-padding-sm bg-fff posi-rela">';
				html+='<li><span class="am-align-left am-margin-0">距离开课：</span>';
				html += "<div class='yomibox' data='"+course[i].startDate+"'></div>";
				html += "</li>";
				html += "<li class='kcyu_libtn' syllabusId='"+course[i].syllabusId +"'>";
				if(course[i].vacancy > 0){
					if(course[i].syllabusState != 5){
						if(course[i].isSchoolId != 0){
							html += "<button class='am-btn am-btn-sm an-btn-999 radius20 am-margin-top-sm am-btn-block posi-rela'>不在校区</button>";
						} else {
							if(course[i].orderState == 1){
								html += "<button class='am-btn am-btn-sm am-btn-blue radius20 am-margin-top-sm am-btn-block posi-rela'>取消预约</button>";
							} else if(course[i].orderState == -1 && course[i].purchaseState != 0){
								html += "<button class='am-btn am-btn-sm am-btn-blue radius20 am-margin-top-sm am-btn-block posi-rela'>立即预约</button>";
							}else if(course[i].orderState == -1 && course[i].purchaseState == 0){
								html += "<button class='am-btn font12 am-btn-sm am-btn-red radius20 am-margin-top-sm am-btn-block posi-rela'>购买课程</button>";
							}
						}          
					}else{
						html += "<button class='am-btn am-btn-sm an-btn-999 radius20 am-margin-top-sm am-btn-block posi-rela'>已结束</button>";
					}
				}
				html += "</li>";
				html += "</ul></div>";
			}
			$("#course").html(html);
			yomi.yomi();
		}
	});
}

//默认将当前日期显示在时间插件中
/*window.onload = function (){
    var date = new Date();
    var year=date.getFullYear();
    var month=date.getMonth()+1;
    var date=date.getDate(); 
    var tim = year+"-"+month+"-"+date;
    document.getElementById("doc-datepicker").value = tim;
}*/






